<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%--
Created by GaoXiang
Date: 2017-03-31 14:16:47 星期五
Version: 1.0
物业添加页面
--%>

<div class="portlet light">

    <div class="portlet-body form">
        <!-- BEGIN FORM-->
        <form action="#" class="form-horizontal" id="save-module">
            <div class="form-body">

                <div class="row">
                    <div class="col-md-6 hide">
                        <div class="form-group">
                            <label class="control-label col-md-3">标识</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" name="id" value="${longId}" placeholder="标识">
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">物业编号</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="number" placeholder="物业编号"
                                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">物业名称</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="name" placeholder="物业名称"
                                       onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
                                       onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">开卡数额</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="cardNumber" placeholder="开卡数额"
                                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">地址</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="address" placeholder="地址">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">邮政编码</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="postcode" placeholder="邮政编码"
                                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">联系电话</label>
                            <div class="col-md-9">
                                <input type="text" id="phone" class="form-control" required name="phone" placeholder="联系电话"
                                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')"
                                        onblur="validate_phone(this.id)">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">邮箱</label>
                            <div class="col-md-9">
                                <input type="text" id="email" class="form-control" required name="email" placeholder="邮箱"
                                        onblur="validate_email(this.id)">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">主页</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="website" placeholder="主页">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">法人</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="legalPerson" placeholder="法人"
                                       onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
                                       onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">法人电话</label>
                            <div class="col-md-9">
                                <input type="text" id="legalPhone" class="form-control" required name="legalPhone" placeholder="法人电话"
                                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')"
                                       onblur="validate_phone(this.id)">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">开户银行</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="bank" placeholder="开户银行"
                                       onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
                                       onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">银行账户</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="bankAccount" placeholder="银行账户"
                                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">税务号</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="taxNumber" placeholder="税务号"
                                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')">
                            </div>
                        </div>
                    </div>

                   <%-- <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">查看权限</label>
                            <div class="col-md-9">
                                &lt;%&ndash;<input type="text" class="form-control" required name="description" placeholder="描述">&ndash;%&gt;
                                <select name="sensitivePower" class="form-control" required>
                                    <option value="">是否可以查看特殊信息权限</option>
                                    <option value="1">可以查看</option>
                                    <option value="0">不可以查看</option>
                                </select>
                            </div>
                        </div>
                    </div>--%>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">描述</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="description" placeholder="描述">
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">常用地址</label>
                            <div class="col-md-9">
                                <input type="text" class="form-control" required name="commonAddress" placeholder="常用地址">
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <div class="form-actions">
                <div class="row">
                    <div class="col-md-6">
                        <div class="row">
                            <div class="col-md-offset-3 col-md-9">
                                <button type="button" class="btn green" onclick="save();">保存物业</button>
                                <button type="button" class="btn default" onclick="layer.close(layer_addModule);">取消</button>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6"> </div>
                </div>
            </div>
        </form>
        <!-- END FORM-->
    </div>
</div>
<!-- script 开始 -->
<script>

    $(function(){
        //初始化页面
        initPage();
    });

    /**
     * 保存物业
     */
    function save(){
        if(validate_phone('phone')==false){
            return ;
        }
        if(validate_phone('legalPhone')==false){
            return ;
        }
        if (validate_email('email')==false){
            return ;
        }
        var param = tools.formParams("save-module");
        if(tools.valid("save-module")){
            tools.post("/estate/save",param,function(data){
                if(data.success){
                    layer.msg('物业保存成功', {icon: 1,time:1000},function(){
                        //刷新列表页面
                        toPage(null);
                        //关闭弹窗
                        layer.close(layer_addModule);
                    });
                }else{
                    tools.errorTip(data.code,data.msg);
                }
            });
        }
    }

/**验证手机号*/
    function validate_phone(id) {
        var validatePhone;
        var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        var phoneValue = $.trim($("#" + id).val());
        if (phoneValue != null && phoneValue != "") {
            if (!myreg.test(phoneValue)) {
                layer.msg("请输入正确的联系方式");
                validatePhone = false;
            } else {
                validatePhone = true;
            }
        } else {
            layer.msg("请输入联系方式");
            validatePhone = false;
        }
        return validatePhone;
    }
/**验证邮箱*/
    function validate_email(id) {
        var validateEmail;
        var myreg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        var emailValue = $.trim($("#" + id).val());
        if (emailValue != null && emailValue != "") {
            if (!myreg.test(emailValue)) {
                layer.msg("请输入正确的邮箱");
                validateEmail = false;
            } else {
                validateEmail = true;
            }
        } else {
            layer.msg("请输入邮箱");
            validateEmail = false;
        }
        return validateEmail;
    }
</script>
<!-- script 结束 -->